package com.project.starter.service;

import com.project.starter.entity.Auth;
import com.project.starter.entity.Blog;
import com.project.starter.mapper.AuthMapper;
import com.project.starter.mapper.BlogMapper;
import org.elasticsearch.action.ingest.IngestActionForwarder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class BlogService {
    @Autowired
    private BlogMapper blogMapper;
    @Autowired
    private AuthMapper authMapper;

    public Blog getBlogById(Integer id) {
        return blogMapper.getBlogById(id);

    }

    public Integer addAuth(Auth auth) {
        return authMapper.addAuth(auth);
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public void addBlogAndAuth(Blog blog) {
        blogMapper.addBlog(blog);
        Auth auth = new Auth();
        auth.setName("default");
        authMapper.addAuth(auth);

    }
}
